package stock;


import java.util.ArrayList;

public class Solution1 {
    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        int[] prices = {7,1,5,3,6,4};
        int res =solution1.maxProfit(prices);
        System.out.println(res);
    }


    //1遍历找到每个数据获利
    //2返回获利最大的
    public int maxProfit(int[] prices){
        int res = getAllValue(prices);
        return res;
    }

    private int getAllValue(int[] prices) {

        int minValue = Integer.MAX_VALUE;
        int result = 0;
        for (int i = 0; i < prices.length; i++) {
            if(prices[i]<minValue){
                minValue = prices[i];
            }else{
                if( prices[i]-minValue>result){
                    result = prices[i]-minValue;
                }
            }
        }
        return result;
    }

}
